package cn.nubia.admin.sysconfig.controller;

import cn.nubia.admin.sysconfig.bean.Dict;
import cn.nubia.admin.sysconfig.query.DictQuery;
import cn.nubia.admin.sysconfig.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by Jason on 2015/7/5.
 */
@Controller
@RequestMapping(value = "/system")
public class DictController {


    @Autowired
    private DictService dictService;


    @RequestMapping(value = "/dictList")
    public ModelAndView getUserList(DictQuery dictQuery) {
        ModelAndView modelAndView = new ModelAndView("/system/dictList");
        List<Dict> dictList = dictService.findList(dictQuery);
        modelAndView.addObject("dictList", dictList);
        return modelAndView;
    }


    @RequestMapping(value = "/saveDict", method = RequestMethod.POST)
    public String save(Dict dict) {
        dictService.save(dict);
        return "redirect:dictList.html";
    }


    @RequestMapping(value = "/viewDict", method = RequestMethod.GET)
    public ModelAndView view(Integer dictId) {
        ModelAndView modelAndView = new ModelAndView("/system/dictForm");
        Dict dict = new Dict();
        if (dictId != null) {
            dict = dictService.get(dictId);
        }
        modelAndView.addObject("dict", dict);
        modelAndView.addObject("dictId", dictId);
        return modelAndView;
    }

    @RequestMapping(value = "/deleteDict", method = RequestMethod.GET)
    public String delete(Integer dictId) {
        dictService.delete(dictId);
        return "redirect:dictList.html";
    }
}
